﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Web.Controllers
{
    public class CompanyAccessController : CommonController
    {
        //
        // GET: /Company/

        public ActionResult Index(string search)
        {
            var data = EdexContext.GetCompanyAccess();
            return View(data);
        }

        public ActionResult Details(Guid id)
        {
            var data = EdexContext.GetCompanyAccessDetails(id);
            return View(data);
        }

        public ActionResult DetailsNew()
        {
            return View();
        }

        public ActionResult Save(EdexApiClient.SEC_COMPANIES_ACCESS record)
        {
            if (record.GUID_RECORD == null || record.GUID_RECORD == Guid.Empty)
                EdexContext.AddCompanyAccess(record);
            else
                EdexContext.UpdateCompanyAccess(record);

            return Content("OK");
        }

        public ActionResult Delete(string id)
        {
            EdexContext.DeleteCompanyAccess(id);
            return Content("OK");
        }

        public ActionResult ProvideAccess()
        {
            EdexContext.AccessToCompany();
            return Content("OK");
        }

        [HttpGet]
        public ActionResult UseAccessCode()
        {
            return View();
        }

        [HttpPost]
        public ActionResult UseAccessCode(string code)
        {
            EdexContext.AccessToCompanyUseKey(code);
            return View("UseAccessCodeComplete");
        }

        public ActionResult ConfirmAccessCode(Guid id)
        {
            EdexContext.AccessToCompanyConfirm(id.ToString());
            return Content("OK");
        }

        public ActionResult RejectAccessCode(Guid id)
        {
            //EdexContext.AccessToCompanyConfirm(id.ToString());
            return Content("OK");
        }
    }
}
